/**
 * Created by LI on 2020/7/7.
 */

public class Lyl {

    public static void main(String[] args) {
        int[] array = {-4, 1, 2, 2, 5, 5, 5, 8, 10};
        int target = 6;
        System.out.println(recursion(array, target, 0, array.length - 1));
    }

    /**
     * 二分查找
     */
    private static int recursion(int[] array, int target, int low, int high) {
        if (low >= high) {
            if (array[low] <= target) {
                return low;
            }
            return low - 1 > 0 ? low - 1 : -1;
        }
        int mid = low + (high - low) / 2;
        if (target < array[mid]) {
            high = mid - 1;
        } else {
            low = mid + 1;
        }
        System.out.println(high + "---" + low + "----" + mid);
        return recursion(array, target, low, high);
    }

}
